# -*- shell-script -*-

# 45adapter_pcichiprev - Get PCI chip revision.

# This file is part of the Linux lsvpd package.

# (C) Copyright IBM Corp. 2004, 2005

# Maintained by Martin Schwenke <martins@au.ibm.com>

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    
# $Id: 45adapter_pci_chiprev,v 1.1 2006/04/11 18:38:28 emunson Exp $

# Don't do this on IBM pSeries.
[ "$device_tree_device_type" = "chrp" ] && return 0

dd_program=$(type -p dd)
[ -n "$dd_program" ] || return 0

######################################################################

adapter_extra_vpd_hooks="${adapter_extra_vpd_hooks} pci_chiprev_extra_vpd_hook"

pci_chiprev_extra_vpd_hook ()
{
    # Sets: key val
    key="" ; val=""

    local bus_type="$1"
    local bus_addr="$2"
    local subtype="$3"

    case "$bus_type" in
	pci)
	    local pci_config
	    pci_get_config_filename "$bus_addr"
	    if [ -r "$pci_config" ] ; then
		local yc=$($dd_program \
		    if="$pci_config" skip=8 bs=1 count=1 2>/dev/null | \
		    tdump)
		if [ -n "$yc" ] ; then
		    key="YC"
		    val=$(hex2dec "$yc")
		fi
	    fi
	    ;;
    esac
}
